import {deepCopy} from "@/utils";
import {getPlanData} from "@/api/shippingPlan";


let cacheFlWarehouseList = [];
let cacheWarehouseList = [];
let cacheTransferTypeList = [];

export default {
  name: 'shippingPlanDataMixin',
  data(){
    return {
      warehouseList: [],
      flWarehouseList: [],
      transferTypeList: [],
    }
  },
  created() {
    this.setPlanData()
    // this.getPlanData()
  },
  methods:{
    setPlanData(){
      if(cacheFlWarehouseList.length === 0 || cacheWarehouseList.length  === 0 || cacheTransferTypeList.length  === 0){
        this.getPlanData()
      }else{
        this.flWarehouseList = cacheFlWarehouseList
        this.warehouseList = cacheWarehouseList
        this.transferTypeList = cacheTransferTypeList
        if(cacheFlWarehouseList.length === 0){
          cacheFlWarehouseList = this.flWarehouseList
        }
        if(cacheWarehouseList.length === 0){
          cacheWarehouseList = this.warehouseList
        }
        if(cacheTransferTypeList.length === 0){
          cacheTransferTypeList = this.transferTypeList
        }
        this.finishWarehouseApi()
      }
    },
    // 获取相关数据
    getPlanData(params = {}){
      getPlanData()
        .then(res=>{
          this.flWarehouseList = deepCopy(res.data.flWarehouseList)
          this.warehouseList = deepCopy(res.data.warehouseList)
          this.transferTypeList = deepCopy(res.data.transferType)
          this.finishWarehouseApi()
        })
    },
    // 获取完api后处理
    finishWarehouseApi(){

    },
    getTransferName(transferType){
      const item = this.transferTypeList.find(item=> item.transferType === transferType)
      return item ? item.typeName : ''
    },
  },
}
